home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / ma90 / macaudio.txt < prev    next >
Encoding:
Text File  |  1990-05-18  |  7.2 KB  |  180 lines

  1. (c)  Copyright 1990 Commodore-Amiga, Inc.   All rights reserved.
  2. The information contained herein is subject to change without notice,
  3. and  is provided "as is" without warranty of any kind, either express
  4. or implied.   The entire risk as to the use of this information is
  5. assumed by the user.
  6.  
  7.  
  8. Reading Mac Sound Files
  9.  
  10. by John Orr
  11.  
  12. There is little difference between the raw data of Amiga and
  13. Apple Macintosh (and Apple IIgs) sound samples.  Both machines
  14. record and play digitized sound in 8-bit samples.  The only
  15. difference between their raw data formats  lies in how the sound
  16. wave is plotted.
  17.  
  18. Sound samples on an Amiga are represented as a positive or
  19. negative offset from zero, ranging from -128 to 127.  A value of
  20. zero represents no sound (see fig. 1).  Mac samples on the other
  21. hand, are represented as a positive offset from zero, but here
  22. zero represents the part of a sound wave that is of the greatest
  23. possible negative amplitude.  Macintosh sample data ranges from 0
  24. to 255 with silence represented by a value of 128 (see fig. 2).  
  25.  
  26. Naturally, the sound data must be converted to cross from one
  27. platform to the other.  Without any conversion, a sine wave
  28. sampled on one platform would look like figure 3 on the other
  29. platform.
  30.  
  31. One simple way to convert a sample from Amiga to Apple format
  32. would be to add 128 to each byte in the sample.  Conversely, to
  33. convert from Apple to Amiga, you could subtract 128 from each
  34. byte.  But both cases can be handled more simply by reversing the
  35. high bit of each byte in the sample.  This one process will
  36. convert a sample of one type to the other.  Hence, performing an
  37. exclusive OR with 0x80 on each byte in the sample will generate
  38. the desired result.
  39.  
  40. Transferring the Data
  41.  
  42. Before converting a Mac audio sample to  Amiga format, another
  43. problem has to be considered: obtaining Mac sound data.  There
  44. are several straight-forward methods of transferring data from
  45. one platform to the other.  A direct serial line transfer can be
  46. performed between the Amiga's RS-232 serial port and the Mac's
  47. RS-422 serial port.  Another way the two machines can share data
  48. is through the use of a product such as Central Coast Software's
  49. Mac-2-DOS which comes with a disk drive that can read and write
  50. both Mac and Amiga formats.  The A-Max Macintosh emulator from
  51. ReadySoft offers yet another convenient way of moving data
  52. across from one platform to the other.
  53.  
  54. Macintosh File Conventions
  55.  
  56. The Mac filing system has an unusual method of storing files. 
  57. Files are broken up into two parts, a data fork and a resource
  58. fork.  In the case of audio samples, the data fork typically
  59. contains the actual sound sample, while the the resource fork
  60. contains various parameters of the sound such as recording and
  61. playback rate.  In general, when transferring Mac files to the
  62. Amiga, only the data fork is needed by the Amiga.  Mac-2-DOS and
  63. most Mac terminal packages are capable of transferring just the
  64. data fork part of the file by itself.  
  65.  
  66. Another thing to note about Mac files is that they have a file
  67. type and creator associated with them.  In the case of sampled
  68. sound files, the file type is FSSD.  When transferring Amiga
  69. files over to the Mac, the file must be given the FSSD file type,
  70. otherwise Mac sound applications generally will not read the
  71. file.  Mac-2-DOS is capable of specifying the file type field as
  72. it copies Amiga files to a Mac floppy.  If you are using some
  73. other transfer method, then the file type can be changed to FSSD
  74. on the Mac end by using a utility such as ResEdit.  
  75.  
  76. The creator field depends on what application created the file. 
  77. A popular sound sampler/editor for the Mac is SoundEdit, which is
  78. akin to the Amiga's AudioMaster II.  SoundEdit's creator field is
  79. SFX!.  
  80.  
  81. It should be mentioned that in certain cases, sound data on a Mac
  82. is stored in the resource fork in an entity known as a sound
  83. resource.  The Mac sys-beep is an example of this.  It is
  84. possible to convert a Mac sound resource to the FSSD file type --
  85. this is left as an exercise for the reader.
  86.  
  87.  
  88. Audio Sample File Formats: Raw vs. IFF
  89.  
  90. When transferring Amiga sounds to the Mac, it's important to
  91. remember that Mac sound samples are usually saved as raw data. 
  92. On the Amiga however, sampled sounds are usually stored in the
  93. IFF 8SVX format. The 8SVX format contains a header chunk called
  94. the VHDR which has global information about the sample such as
  95. the sampling rate and compression used.  This is followed by a
  96. BODY chunk which contains the raw sound data.  For the Mac to
  97. interpret an Amiga sample correctly, only the raw data should be
  98. present.  Likewise, a Mac sample should be converted to 8SVX for
  99. use on the Amiga.
  100.  
  101. SunRize Industries' Perfect Sound is capable of reading and
  102. writing both raw sound data and IFF 8SVX data which makes it a
  103. handy conversion tool.  Another option is Aegis' AudioMaster II
  104. software which includes a utility that can strip an 8SVX file
  105. down to a raw data file.  Note that for  stereo samples, both
  106. platforms store the raw data in the same order -- the left
  107. channel first followed by the right channel.  So, stereo and mono
  108. samples are converted using the same methods.
  109.  
  110. Recently, Apple adopted another standard for storing sound
  111. samples.  It is based on the IFF model of data storage and is
  112. called the Audio Interchange File Format (AIFF).  It is similar
  113. in many ways to 8SVX, but is intended to be more versatile.  The
  114. AIFF standard has not yet been widely accepted, and consequently,
  115. commonly found samples are not stored in this format.  More
  116. information on this format can be found in Apple documentation.
  117.  
  118. Sampling Speeds
  119.  
  120. After a sound sample has been copied from one medium to the
  121. other, a playback rate has to be determined since this
  122. information is not preserved in transferring raw data.  Mac
  123. sounds digitized with SoundEdit and MacRecorder -- a popular Mac
  124. sound digitizer -- are sampled at four different speeds: 22kHz,
  125. 11kHz, 7kHz, and 5kHz.  Amiga audio samples normally vary in
  126. recording speed and can be as fast as 28,867 bytes/second.  The
  127. table below shows the four MacRecorder sampling rates and their
  128. Amiga equivalents.
  129.  
  130.  
  131. The example code below will convert raw sound samples to and from
  132. the Amiga and Mac formats.  It is important to remember that this
  133. program works only with raw data.  8SVX samples must be stripped
  134. of the added IFF information, before they can be converted. 
  135.  
  136.  
  137.  
  138. /*
  139. * convertsound.c - Converts raw sound data back and
  140. * forth from a Macintosh/Apple IIgs format to the Amiga
  141. * format.
  142. */
  143.  
  144. #include <exec/types.h>
  145. #include <libraries/dosextens.h>
  146.  
  147. #define BUFSIZE 32767
  148.  
  149. struct FileHandle *Open(char *, LONG);
  150.  
  151. UBYTE buffer[BUFSIZE];
  152.  
  153. void main(int argc, char **argv)
  154. {
  155.     struct FileHandle *fh_in, *fh_out;
  156.     WORD count_in, count_out, x = 0;
  157.  
  158.     if (argc != 3)
  159.     {
  160.         printf("usage:\n\t%s <infile> <outfile>",argv[0]);
  161.         exit(30);
  162.     }
  163.     if (fh_in = Open(argv[1], MODE_OLDFILE))
  164.     {
  165.         if (fh_out = Open(argv[2], MODE_NEWFILE))
  166.         {
  167.             do
  168.             {
  169.                 count_in = Read(fh_in, buffer, BUFSIZE);
  170.                 for (x=0; x < count_in; x++) 
  171.                          buffer[x] ^= 0x80;
  172.                 count_out = Write(fh_out, buffer, count_in);
  173.             } while (count_in > 0);
  174.  
  175.             Close(fh_out);
  176.         }
  177.         Close(fh_in);
  178.     }
  179. }
  180.